package cn.itcast.mapper;

import cn.itcast.pojo.Emp;
import cn.itcast.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmpMapper {

    /*1.这是最原始的方式*/
//    @Select("select e.*,d.name deptName from emp e left outer join dept d on e.dept_id = d.id order by update_time desc limit #{start},#{pageSize}")
//    List<Emp> page(@Param("start") Integer start,
//                   @Param("pageSize") Integer pageSize);

//    @Select("select count(*) from emp")
//    long count();

    /*2.（利用PageHelper要写动态SQl*/
/*    @Select("select e.*,d.name deptName from emp e left outer join dept d on e.dept_id = d.id order by update_time desc")
    List<Emp> page();*/

    /**
     * @param empQueryParam
     *requires @return
     */
    /*3.基于动态SQL*/
    /*实体类不要加@param*/
    List<Emp> page(EmpQueryParam empQueryParam);

    /*是否自动增长，键属性 = id */


//    @Options(useGeneratedKeys = true,keyProperty = "id")
//    @Insert("insert into emp (username,password,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) " +
//            " value (#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void save(Emp emp);


    List<Emp> list();


    void deleteBatchById(@Param("ids") List<Integer> ids);

    Emp getEmpById(Integer id);

    void updateEmp(Emp emp);
    @Select("select count(*) from emp where dept_id =#{id}")
    Integer countByDeptID(@Param("id") Integer id);

    @Select("select * from emp where username =#{username}")
    Emp getEmpByUsername(@Param("username") String username);
}
